﻿using nplJobsCommon.JobSeeker;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace nplJobsDAL.Select
{
    public class SelectJobSeekerLanguageProficiency: DataAccessBase
    {
        public Guid JobSeekerID { get; set; }

        public SelectJobSeekerLanguageProficiency()
        {
            StoredProcedureName = StoredProcedure.Name.spSelectJobSeekerLanguageProficiencyByJobSeekerID.ToString();
        }

        #region GetJobSeekerLanguageProficiency
        public List<JobSeekerLanguageProficiency> GetJobSeekerLanguageProficiency()
        {
            DataBaseHelper dbHelper;
            DataSet dsJobSeekerLanguageProficiency;

            try
            {
                SelectJobSeekerLanguageProficiencyParameters selectJobSeekerParameters = new SelectJobSeekerLanguageProficiencyParameters(this.JobSeekerID);
                dbHelper = new DataBaseHelper(StoredProcedureName);
                dbHelper.Parameters = selectJobSeekerParameters.Parameters;
                dsJobSeekerLanguageProficiency = dbHelper.Run(base.ConnectionString, dbHelper.Parameters);
                return GetList(dsJobSeekerLanguageProficiency);
            }
            catch (Exception)
            {
                throw;
            }
        }
        #endregion



        #region SQL parameters for selecting job seeker language proficiency by jobseeker id
        public class SelectJobSeekerLanguageProficiencyParameters
        { 
            private SqlParameter[] _parameters;

            public SelectJobSeekerLanguageProficiencyParameters(Guid jobSeekerID)
            {
                this.JobSeekerID = jobSeekerID;
                Build();
            }
            private void Build()
            {
                SqlParameter[] parameters = 
                {
                    new SqlParameter("@JobSeekerID", JobSeekerID),
                };

                Parameters = parameters;
            }

            public Guid JobSeekerID { get; set; }

            public SqlParameter[] Parameters
            {
                get { return _parameters; }
                set { _parameters = value; }
            }
        }
        #endregion
        #region GetList
        private List<JobSeekerLanguageProficiency> GetList(DataSet dsJobSeekerLanguageProficiency)
        {
            List<JobSeekerLanguageProficiency> jobSeekerLanguageProficiency;
            try
            {
                jobSeekerLanguageProficiency = (from n in dsJobSeekerLanguageProficiency.Tables[0].AsEnumerable()
                             select new JobSeekerLanguageProficiency
                                {
                                    ID = n.Field<int>("JobSeekerProficiencyID"),
                                    JobSeekerID = n.Field<Guid>("JobSeekerID"),
                                    Proficiency = n.Field<string>("Proficiency"),
                                    Language = n.Field<string>("Language"),
                                    ProficiencyID = n.Field<int>("ProficiencyID"),
                                    LanguageID = n.Field<int>("LanguageID")
                                }).ToList();

                return jobSeekerLanguageProficiency;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally { }
        }
        #endregion

    }
}
